//
//  HJPersonalCenterAvatarCell.m
//  KaiChat
//
//  Created by lx on 2023/12/14.
//

#import "HJPersonalCenterAvatarCell.h"

 

@interface HJPersonalCenterAvatarCell()

@property (nonatomic, weak) UIView *lineView;
@property (nonatomic, weak) UIImageView *arrowImageView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UIImageView *avatarImageView;


@end


@implementation HJPersonalCenterAvatarCell



- (void)settingSubView {
 
    self.backgroundColor = UIColor.whiteColor;
    
    _titleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.centerY.offset(0);
    }];
    
    _arrowImageView = [UIImageView addToView:self.contentView];
    _arrowImageView.image = [UIImage imageNamed:@"cell_arrow"];
    [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.centerY.offset(0);
    }];
    
    _lineView = [UIView addToView:self.contentView];
    _lineView.backgroundColor = [UIColor.tj_CCCCCCColor colorWithAlphaComponent:0.2];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.bottom.offset(0);
        make.height.offset(lineHeight);
    }];
    
    _avatarImageView = [UIImageView addToView:self.contentView];
    _avatarImageView.addCornerRadius(20);
    [_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_arrowImageView.mas_left).inset(8);
        make.centerY.offset(0);
        make.width.height.offset(40);
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleModifyAvatarSucceedNotification:) name:modifyAvatarSucceedNotification object:nil];
}

- (void)handleModifyAvatarSucceedNotification:(NSNotification *)not {
    UIImage *image = not.object;
    _avatarImageView.image = image;
}

- (void)setModel:(HJCellModel *)model {
    _model = model;
    
    _titleLabel.text = model.text;
    _lineView.hidden = !model.showLine;
    [_avatarImageView tj_setImageWithUrl:model.detailText placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    _titleLabel.font = model.textFont ?: UIFontMake(14);
    _titleLabel.textColor = model.textColor ?: UIColor.tj_333333Color;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:modifyAvatarSucceedNotification object:nil];
}
 

@end
